package com.zhanghaijun.web.controller.user;

import com.zhanghaijun.domain.ZUserBean;
import com.zhanghaijun.dto.JsonResultDto;
import com.zhanghaijun.service.ZUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by zhanghaijun on 15/9/6.
 */
@Controller
public class UserController {

    /**
     * 登陆接口
     * @param username
     * @param password
     * @return
     */
    @RequestMapping(value = "/user/login/{username}/{password}")
    @ResponseBody
    public JsonResultDto login(@PathVariable("username") String username,@PathVariable("password") String password){
       ZUserBean userMsg =  zUserService.login(username, password);
       if(userMsg!=null){
           return new JsonResultDto(true,101,userMsg);
       }else{
           return new JsonResultDto(false);
       }
    }

    /**
     * 用户列表接口
     * @return
     */
    @RequestMapping(value = "/user/list")
    @ResponseBody
    public JsonResultDto list(){
        return  new JsonResultDto(true,101,zUserService.getList());
    }


    /**
     * 用户详情
     * @return
     */
    @RequestMapping(value = "/user/detail/{uid}")
    @ResponseBody
    public JsonResultDto getUserByUid(@PathVariable("uid") Long uid){
        return  new JsonResultDto(true,101,zUserService.getById(uid));
    }

    @Autowired
    ZUserServiceImpl zUserService;


}
